package com.zhongmeng.newsdemo;

import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;
import android.content.Intent;
import android.view.animation.AccelerateInterpolator;
import android.widget.ImageView;
import android.widget.TextView;

import com.zhongmeng.newsdemo.base.BaseActivity;
import com.zhongmeng.newsdemo.ui.activity.MainActivity;

import butterknife.BindView;


public class SplashActivity extends BaseActivity {

    @BindView(R.id.iv_logo)
    ImageView ivLogo;
    @BindView(R.id.tv_name)
    TextView tvName;

    @Override
    public int getLayoutId() {
        return R.layout.activity_splash;
    }

    @Override
    public void initView() {
        PropertyValuesHolder alpha=PropertyValuesHolder.ofFloat("alpha",0.3f,1.0f);
        PropertyValuesHolder scaleX=PropertyValuesHolder.ofFloat("scaleX",0.3f,1.0f);
        PropertyValuesHolder scaleY=PropertyValuesHolder.ofFloat("scaleY",0.3f,1.0f);

        ObjectAnimator nameAnimator=ObjectAnimator.ofPropertyValuesHolder(tvName,alpha,scaleX,scaleY);
        ObjectAnimator logoAnimator=ObjectAnimator.ofPropertyValuesHolder(ivLogo,alpha,scaleX,scaleY);

        AnimatorSet animatorSet=new AnimatorSet();
        animatorSet.playTogether(nameAnimator,logoAnimator);
        animatorSet.setInterpolator(new AccelerateInterpolator());
        animatorSet.setDuration(2000);
        animatorSet.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animator) {

            }

            @Override
            public void onAnimationEnd(Animator animator) {
                Intent intent=new Intent(SplashActivity.this,MainActivity.class);
                startActivity(intent);
                overridePendingTransition(R.anim.fade_in,R.anim.fade_out);
                finish();
            }

            @Override
            public void onAnimationCancel(Animator animator) {

            }

            @Override
            public void onAnimationRepeat(Animator animator) {

            }
        });
        animatorSet.start();

    }

    @Override
    public void addListener() {

    }
}
